﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Common.BLL;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing;
using Yipusoft.SecurityEvaluate;

public partial class Police_Question_View2 : System.Web.UI.Page
{
    private string[] charts = { "Column", "Spline", "StepLine", "Spline" };
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Bind();
    }
    private void Bind()
    {

        if (Request["ID"] == null || Request["DepartmentID"] == null)
            return;
        string Departmentid = Request["DepartmentID"];
        DataView dv = SecurityEvaluateAnalyse.SecurityDetachmentAnalyse(new Guid(Request["ID"]), Departmentid).DefaultView;
        Chart1.Series["未超出警戒线单位"].Points.DataBindXY(dv, "ShortName", dv, "Score");

        for (int i = 0; i < dv.Table.Rows.Count; i++)
        {
            Chart1.Series["未超出警戒线单位"].Points[i].Url = "AnswerAnlyse2.aspx?DepartmentID=" + dv.Table.Rows[i]["DepartmentID"] + "&ID=" + Request["ID"] + "";
        }
        QuestionDataContext db = new QuestionDataContext();
        var obj = (from o in db.SecurityProblem where (from s in db.SecuritySubject where s.Id == new Guid(Request["ID"]) select s.Id).Contains(o.Sid.Value) select o);

        decimal Standard = obj.Sum(o => o.GuardCount).Value / obj.Count();

        // add a series to the chart
        Series series = Chart1.Series.Add("警戒线");
        series.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), charts[Chart1.Series.Count - 1], true);
        series.BorderWidth = 1;
        series.BorderColor = Color.Red;
        series.ShadowOffset = 0;
        series.Color = Color.Red;
        int j = 0;
        string Department = string.Empty;

        while (j++ < Chart1.Series["未超出警戒线单位"].Points.Count)
        {
            double temp = double.Parse(Standard.ToString());
            series.Points.Add(temp / 100);

        }
        for (int i = 0; i < dv.Table.Rows.Count - 1; i++)
        {
            if (dv.Table.Rows[i][1] == DBNull.Value)
                break;

            if (decimal.Parse(dv.Table.Rows[i][1].ToString()) * 100 >= Standard)
            {
                Department += dv.Table.Rows[i][0] + "、";
                Chart1.Series["未超出警戒线单位"].Points[i].Color = Color.FromArgb(200, 0, 0);
            }

        }
        if (Department != string.Empty)
        {
            Department = Department.Remove(Department.Length - 1);
            lbljinggao.Text = "<font color=red>警告：</font>" + Department + "已超出警戒线";
        }
        Chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = false;
        Chart1.Series["未超出警戒线单位"].LabelFormat = "p0";

        //RemoveButton.Enabled = Chart1.Series.Count > 1;
        //AddButton.Enabled = Chart1.Series.Count < charts.Length;
        lblRemark.Text = "<font color=green>备注：</font>" + "如果各大中队超出警戒线柱状图将变为红色";
    }

}
